﻿Public Class User

  'параметры пользователя
  Public ID_Worker As String
  Public ID_Post As String
  Public FIO As String
  Public RightUser As String

  'параметры отдела
  Public ID_Otdel As String
  Public ID_MOtdel As String
  Public NBOtdel As String

  'параметры организации
  Public ID_CurOrg As String
  Public NameCurOrg As String
  Public NameBrCurOrg As String

  ''' <summary>
  ''' Загрузка данных пользователя
  ''' </summary>
  Public Sub LoadUserInfo()

    Dim UserName As String = Environment.UserName

    'UserName = "KondratenkoAI"

    'проверка на соответствие имени пользователя (для разработчиков)
    If UserName.ToUpper() = "DGK" Then
      UserName = "IsaevEN"
    End If

    Dim SqlStr As String = "SELECT Workers.ID_Worker, Workers.F_Worker + ' ' + Workers.I_Worker AS FIO, "
    SqlStr += " Workers.ID_Post, Workers.ID_Otdel, Otdels.NB_Otdel AS NBOtdel, Otdels.Part"
    SqlStr += " FROM Workers INNER JOIN"
    SqlStr += " Otdels ON Workers.ID_Otdel = Otdels.ID_Otdel"
    SqlStr += " WHERE Workers.Fl_Rel = 0 AND Workers.Login = '" + UserName + "'"

    Dim DRC As DataRowCollection = DB.GetFields(SqlStr)

    'пользователь не найден, сообщение и выход
    If DRC.Count = 0 Then
      UI.MsgErr("Ошибка аутентификации пользователя" + vbNewLine + "Обратитесь к администратору")
      'выход из приложения
      System.Environment.Exit(0)
    End If

    'строка данных из таблицы
    Dim dr As DataRow = DRC(0)

    ID_Worker = dr("ID_Worker").ToString()
    FIO = dr("FIO").ToString()
    ID_Post = dr("ID_Post").ToString()

    ID_Otdel = dr("ID_Otdel").ToString()

    If dr("Part").ToString() = "" Then
      ID_MOtdel = ID_Otdel
    Else
      ID_MOtdel = dr("Part").ToString()
    End If

    NBOtdel = dr("NBOtdel").ToString()


    'права пользователя:
    Params.UserInfo.RightUser = "user"
    SqlStr = "SELECT * FROM RUsers WHERE (((RUsers.ID_Worker)=" + Params.UserInfo.ID_Worker + ") AND ((RUsers.Application)='SSPD'))"
    DRC = DB.GetFields(SqlStr)
    If DRC.Count > 0 Then
      RightUser = DRC(0)("RightWorker").ToString()
    End If

    'данные организации
    SqlStr = "SELECT ID_Org, Name, Name_Br From Orgs " + "WHERE (ID_Org = (SELECT RTRIM(LTRIM(Val_Par)) AS IDO From Params WHERE (ID_Par = 10)))"
    DRC = DB.GetFields(SqlStr)
    If DRC.Count > 0 Then
      ID_CurOrg = DRC(0)("ID_Org").ToString()
      NameCurOrg = DRC(0)("Name").ToString()
      NameBrCurOrg = DRC(0)("Name_Br").ToString()
    End If



  End Sub

End Class
